<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>数据跑批测试</title>
</head>
<body>
<div align="left">
    <form enctype="multipart/form-data" method="post" id="tf">
        文件：<input type="file" name="file_item" id="file_item"><br>
        <!--接口名称：<input type="text" name="interfaceName" value="personCreditBatch" id="interfaceName"><br>-->
        接口名称：<select name="interfaceName" id="interfaceName">
                    <option value="personCreditBatch">人员从业资格(personCredit)</option>
                    <option value="vehicleCreditBatch">车辆道运证(vehicleCredit)</option>
                    <option value="enterpriseCreditBatch">车辆道运证(enterpriseCreditBatch)</option>
                    <option value="vehicleLicenseInfoCheckBatch">行驶证信息(vehicleLicenseInfoCheck)</option>
                    <option value="personCriminalBatch">不良记录(personCriminal)</option>
                    <option value="realnameBatch">实名认证(realname)</option>
                    <option value="drivingQueryInfoBatch">驾驶证(drivingQueryInfo)</option>
                    <option value="vehicleviolationinqueryInfoBatch">违章信息(vehicleviolationinqueryInfo)</option>
                    <option value="preApprovalBatch">预授信(preApproval)</option>
                    <option value="addressValidateBatch">高德-地址核验-欺诈系数(addressValidate)</option>
                </select><br>
        是否解析：
        <select name="analysisLevelOne" id="analysisLevelOne">
            <option value="false">不解析</option>
            <option value="true">解析</option>
        </select><br>
        <input type="hidden" name="partner_key" value="12752qw196014AFFE5729CC500Ef396" id="partner_key">
        <input type="hidden" name="partner_code" value="shtxdev" id="partner_code"><br>
        <input type="hidden" name="app_type" value="file"><br>
        <input type="hidden" name="file_name" value="file_name" id="file_name"><br>
        <input type="hidden" name="upload" value=false id="upload"><br>
        <input type="button" value="提交" onclick="test()">
    </form>
    <button onclick="test3('2017-03-03','测试')">测试测试</button>



    <span id="errorMsg"></span>


</div>
<script src="https://cdn.bootcss.com/jquery/1.12.4/jquery.min.js"></script>
<script>

    // var baseUrl="https://api.st-creditech.com";
    // var baseUrl="https://api.st-creditech.com";

    var baseUrl="http://localhost:8080";

    var fileName;
    var newFileName;

    function test() {
        var form = new FormData(document.getElementById("tf"));

        var interfaceName = $("#interfaceName").val();
        var analysisLevelOne = $("#analysisLevelOne").val();
        var upload = true;
        var ajax2;
        ajax1 = $.ajax({
            url: baseUrl+"/file/external/fileUpload",
            type: "post",
            data: form,
            async: true,
            processData: false,
            contentType: false,
            success: function (data) {
                data = JSON.parse(data);
                if (!data.success) {
                    alert("上传文件失败：" + data.data.stateCode.desc);
                    return false;
                } else {
                    newFileName = data.data.fileName;
                }
                console.log("over1..");
            },
            error: function (e) {
                alert("错误！！" + e);
            }
        });
        $.when(ajax1).done(function () {
            var ajax2_fileName;
            var ajax2_uuidName;
            ajax2 = $.ajax({
                url: baseUrl+"/api/data/dataBatchCall",
                type: "post",
                data: "partner_key=" + $("#partner_key").val() + "&partner_code=" + $("#partner_code").val() + "&interfaceName=" + interfaceName + "&fileName=" + fileName +
                    "&uuidName=" + newFileName + "&analysisLevelOne=" + analysisLevelOne +"&isUpload ="+upload,
                processData: false,
                success: function (data) {
                    // data = JSON.parse(data);
                    // if (data.success) {
                    //     $("#download_file_name").val(data.display.fileName)
                    //     $("#download_uuid_name").val(data.display.newName)
                    //     ajax2_fileName = data.display.fileName;
                    //     ajax2_uuidName = data.display.newName;
                    //     $("#download").submit();
                    // }else{
                    //     alert(data)
                    //     alert(JSON.stringify(data))
                    //     // var rowIds = data.display.errorData;
                    //     // $.each(rowIds,function (index,value) {
                    //     //     $("#errorMsg").append("<p style='color: red;'>第"+JSON.stringify(rowIds[index].rowId)+"行，"+JSON.stringify(rowIds[index].errorMsg)+"</p>")
                    //     // })
                    // }
                    alert(data)
                    console.log("over2..");
                },
                error: function (e) {
                    alert(e)
                }
            });
        });
    }
    function test1(dateStr,textStr,finalDateStr,finalTextStr){
        var map = {};
        var a = dateStr.length%10;
        for (i = 1; i <= a; i++) {
            var k = dateStr.substring()
        }
    }

    function test3(dateStr,textStr){
        var a = "2013-01-01|2014-01-02|2015-04-02|2016-03-02|2018-04-04";
        var b = "募集开始|募集结束|起息日|到期日|兑付日";

        //将原字符串转换为数组
        var arr = a.split("|");
        //将每个元素中-去掉
        for(i=0;i<arr.length;i++){
            arr[i]=arr[i].replace("-","").replace("-","");
        }


        //将入参的日期字符串的-去掉
        var newDateStr=dateStr.replace("-","").replace("-","");
        //要插入的位置
        var index = 0;
        //循环比较计算将要插入的日期应该在第几个位置
        for(i=0;i<arr.length;i++){
            if(parseInt(arr[i])<parseInt(newDateStr)){
                index++
            }
        }

        //将原数组重新分组，准备返回，arr已经被截取改变，所以不能再使用
        var finalDateArr = a.split("|");
        var finalTextArr = b.split("|");
        //插入原日期字符串，根据计算出的index，finalArr[index]后面的元素后移
        for(i=finalDateArr.length;i>=index;i--){
            finalDateArr[i+1]=finalDateArr[i];
            finalTextArr[i+1]=finalTextArr[i];
        }
        //index位置插入元素
        finalDateArr[index] = dateStr;
        finalTextArr[index] = textStr;
        //添加分割线
        var finalDateStr=finalDateArr.join("|");
        var finalTextStr=finalTextArr.join("|");
        //去掉最后一个分割线
        finalDateStr = finalDateStr.substring(0,finalDateStr.length-1);
        finalTextStr = finalTextStr.substring(0,finalTextStr.length-1);
        alert(finalDateStr);
        alert(finalTextStr);


    }


    $("#file_item").change(function () {
        var file = $('#file_item').get(0).files[0];
        if (file) {
            var fileSize = 0;
            if (file.size > 1024 * 1024) fileSize = (Math.round(file.size * 100 / (1024 * 1024)) / 100).toString() + 'MB';
            else fileSize = (Math.round(file.size * 100 / 1024) / 100).toString() + 'KB';
            $("#file_name").val(file.name)
            fileName = file.name;
            console.log(fileName);
            console.log(file.name, fileSize, file.type);
        }
    });
</script>
</body>
</html>